package com.judian.smart.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.judian.smart.R;
import com.judian.smart.holder.FamilyViewHolder;
import com.judian.smart.interfaces.OnListItemClickListener;
import com.judian.smart.model.Archive;

import java.util.List;

/**
 * author: Peter
 * date: 2019/08/12 星期一 10:43
 * desc:
 */
public class FamilyAdapter extends RecyclerView.Adapter<FamilyViewHolder> {
    private List mList;
    private Context mContext;

    public OnListItemClickListener<Archive> mListener = null;

    public FamilyAdapter(Context context, List list) {
        mList = list;
        mContext = context;
    }

    @NonNull
    @Override
    public FamilyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new FamilyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.family_list_item_layout, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull FamilyViewHolder holder, final int position) {
        final Archive archive = (Archive) mList.get(position);
        holder.familyName.setText(archive.getProjectName());
        holder.familyPassword.setText(archive.getProjectPwd());
        holder.dateText.setText(archive.getProjectTime());
        holder.itemLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mListener.setOnItemClick(archive, position);
            }
        });
    }

    public void setList(List list) {
        mList = list;
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }
}
